package com.skyjoo.search.test.stock;

import org.apache.lucene.document.Document;
import org.apache.lucene.facet.FacetResult;

import com.skyjoo.search.lucene.index.search.FacetCallback;
import com.skyjoo.search.lucene.index.search.LuceneIndexSearcher;

public class StockSearchServiceImpl implements StockSearchService {

    private LuceneIndexSearcher indexSearcher;

    @Override
    public void search(StockQuery query) {

        // indexSearcher.search(query, new Callback<Stock>() {
        //
        // @Override
        // public Stock convertFrom(Document document) {
        // String stockName = document.get("name");
        // Stock stock = new Stock();
        // stock.setStockName(stockName);
        // return stock;
        // }
        // });

        indexSearcher.searchForFacets(query, new FacetCallback<Stock, StockTaxon>() {

            @Override
            public Stock convertFrom(Document document) {
                String stockName = document.get("name");
                Stock stock = new Stock();
                stock.setStockName(stockName);
                return stock;
            }

            @Override
            public StockTaxon convertFrom(FacetResult fr) {
                // TODO Auto-generated method stub
                return new StockTaxon();
            }
        });

    }

    public LuceneIndexSearcher getIndexSearcher() {
        return indexSearcher;
    }

    public void setIndexSearcher(LuceneIndexSearcher indexSearcher) {
        this.indexSearcher = indexSearcher;
    }

}
